import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/home/index'),
        meta: { title: '首页' }
      },
      {
        path: 'personInfo',
        name: 'personInfo',
        component: () => import('@/views/person_info'),
        meta: { title: '个人信息' }
      },
    ]
  },
  {
    path: "/workFlow",
    name: "workFlow",
    component: Layout,
    redirect: "/workFlow/modelManage",
    children: [
      {
        path: "modelManage",
        name: "modelManage",
        component: () => import("@/views/workFlow/modelManage"),
        meta: {
          keepAlive: true,
          title: "模型管理",
        }
      },
      {
        path: "flowManage",
        name: "flowManage",
        component: () => import("@/views/workFlow/flowManage"),
        meta: {
          keepAlive: true,
          title: "流程管理",
        }
      },
      {
        path: "runningFlow",
        name: "runningFlow",
        component: () => import("@/views/workFlow/runningFlow"),
        meta: {
          keepAlive: true,
          title: "运行中流程",
        }
      },
      {
        path: "historyFlow",
        name: "historyFlow",
        component: () => import("@/views/workFlow/historyFlow"),
        meta: {
          keepAlive: true,
          title: "历史流程",
        }
      },
    ],
    meta: {
      keepAlive: true,
      title: "工作流程",
    }
  },
  {
    path: "/taskManage",
    name: "taskManage",
    component: Layout,
    redirect: "/taskManage/needToTask",
    children: [
      {
        path: "needToTask",
        name: "needToTask",
        component: () => import("@/views/taskManage/needToTask"),
        meta: {
          keepAlive: true,
          title: "待办任务",
        }
      },
      {
        path: "doneToTask",
        name: "doneToTask",
        component: () => import("@/views/taskManage/doneToTask"),
        meta: {
          keepAlive: true,
          title: "已办任务",
        }
      },
    ],
    meta: {
      keepAlive: true,
      title: "任务管理",
    }
  },
  {
    path: "/applyApproval",
    name: "applyApproval",
    component: Layout,
    redirect: "/applyApproval/leaveApproval",
    children: [
      {
        path: "leaveApproval",
        name: "leaveApproval",
        component: () => import("@/views/applyApproval/leaveApproval"),
        meta: {
          keepAlive: true,
          title: "请假审批",
        }
      },
    ],
    meta: {
      keepAlive: true,
      title: "申请审批",
    }
  },
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
